package me.zhihui.jsaot.processor;
//package me.zhihui.jsaot.listener;
///***
// * Excerpted from "The Definitive ANTLR 4 Reference",
// * published by The Pragmatic Bookshelf.
// * Copyrights apply to this code. It may not be used to create training material, 
// * courses, books, articles, and the like. Contact us if you are in doubt.
// * We make no guarantees that this code is fit for any purpose. 
// * Visit http://www.pragmaticprogrammer.com/titles/tpantlr2 for more book information.
//***/
//import me.zhihui.jsaot.symbol.FunctionSymbol;
//import me.zhihui.jsaot.symbol.GlobalScope;
//import me.zhihui.jsaot.symbol.Scope;
//import me.zhihui.jsaot.symbol.Symbol;
//import me.zhihui.jsaot.symbol.VariableSymbol;
//
//import org.antlr.v4.runtime.tree.ParseTreeProperty;
//
//public class RefPhase extends CymbolBaseListener {
//    ParseTreeProperty<Scope> scopes;
//    GlobalScope globals;
//    Scope currentScope; // resolve symbols starting in this scope
//
//    public RefPhase(GlobalScope globals, ParseTreeProperty<Scope> scopes) {
//        this.scopes = scopes;
//        this.globals = globals;
//    }
//    public void enterFile(CymbolParser.FileContext ctx) {
//        currentScope = globals;
//    }
//
//    public void enterFunctionDecl(CymbolParser.FunctionDeclContext ctx) {
//        currentScope = scopes.get(ctx);
//    }
//    public void exitFunctionDecl(CymbolParser.FunctionDeclContext ctx) {
//        currentScope = currentScope.getEnclosingScope();
//    }
//	
//    public void enterBlock(CymbolParser.BlockContext ctx) {
//        currentScope = scopes.get(ctx);
//    }
//    public void exitBlock(CymbolParser.BlockContext ctx) {
//        currentScope = currentScope.getEnclosingScope();
//    }
//
//    public void exitVar(CymbolParser.VarContext ctx) {
//        String name = ctx.ID().getSymbol().getText();
//        Symbol var = currentScope.resolve(name);
//        if ( var==null ) {
//            CheckSymbols.error(ctx.ID().getSymbol(), "no such variable: "+name);
//        }
//        if ( var instanceof FunctionSymbol ) {
//            CheckSymbols.error(ctx.ID().getSymbol(), name+" is not a variable");
//        }
//    }
//
//    public void exitCall(CymbolParser.CallContext ctx) {
//        // can only handle f(...) not expr(...)
//        String funcName = ctx.ID().getText();
//        Symbol meth = currentScope.resolve(funcName);
//        if ( meth==null ) {
//            CheckSymbols.error(ctx.ID().getSymbol(), "no such function: "+funcName);
//        }
//        if ( meth instanceof VariableSymbol ) {
//            CheckSymbols.error(ctx.ID().getSymbol(), funcName+" is not a function");
//        }
//    }
//}
